<template>
	<div id="updatesickperson">



		<el-form :model="insertFrm" ref="insertFrm">

			<el-row>
				<el-col :span="3">
					<i class="el-icon-edit" style=""></i>
					<font size="4" style="color: black;"><b>编辑患者信息</b></font>
				</el-col>
				<el-col :span="3">
					<el-button type="primary" @click="UpdateData" style="margin-left: 850px;">保存</el-button>
					</el-col>
				<el-col :span="3">
					<el-button type="primary" @click="backData" style="margin-left: 770px;">返回</el-button>
				</el-col>
			</el-row>

			<el-row>
				<el-col :span="4">
					<font size="6" style="color: cornflowerblue;left: -500px;">患者基本信息</font>
				</el-col>
			</el-row>

			<!-- 第一行 -->
			<el-row>
				<el-col :span="6">
					<el-form-item label="患者姓名">
						<el-input v-model="insertFrm.name" placeholder="请输入患者姓名" style="width: 290px;"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6">
					<el-form-item label="患者卡号">
						<el-input v-model="insertFrm.serialnumber" placeholder="请输入患者卡号" style="width: 290px;"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6">
					<el-form-item label="患者年龄">
						<el-input v-model="insertFrm.age" placeholder="请输入患者年龄" style="width: 290px;"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6">
					<el-form-item label="出生日期">
						<el-date-picker v-model="insertFrm.birth" value-format="yyyy-MM-dd" style="width: 290px;" placeholder="请输入出生日期">
						</el-date-picker>
					</el-form-item>
				</el-col>
			</el-row>

			<!-- 第二行 -->
			<el-row>
				<el-col :span="6">
					<el-form-item label="性别">
						<el-select v-model="insertFrm.sex" placeholder="请选择性别" style="width: 290px;">
							<el-option :id="0" :value="0">女</el-option>
							<el-option :id="1" :value="1">男</el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="6">
					<el-form-item label="手机号码">
						<el-input v-model="insertFrm.phone" placeholder="请输入手机号码" style="width: 290px;"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6">
					<el-form-item label="证件号码">
						<el-input v-model="insertFrm.personid" placeholder="请输入证件号码" style="width: 290px;"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6">
					<el-form-item label="患者来源">
						<el-select v-model="insertFrm.sourceId" placeholder="请选择患者来源" style="width: 290px;">
							<el-option v-for="sou in source" :label="sou.name" :value="sou.id"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
			</el-row>

			<!-- 第三行 -->
			<el-row>
				<el-col :span="6">
					<el-form-item label="会员类型">
						<el-select v-model="insertFrm.vipgradeId" placeholder="请选择会员类型" style="width: 290px;">
							<el-option v-for="vip in vipgrade" :label="vip.name" :value="vip.id"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="6">
					<el-form-item label="到期时间">
						<el-date-picker v-model="insertFrm.vipenddate" value-format="yyyy-MM-dd" style="width: 290px;" placeholder="请输入到期时间">
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="6">
					<el-form-item label="民族">
						<el-input v-model="insertFrm.nation" placeholder="请输入民族" style="width: 290px;"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6">
					<el-form-item label="婚姻状况">
						<el-select v-model="insertFrm.maritalId" placeholder="请选择婚姻状况" style="width: 290px;">
							<el-option v-for="mar in marital" :label="mar.name" :value="mar.id"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
			</el-row>

			<!-- 第四行 -->
			<el-row>
				<el-col :span="6">
					<el-form-item label="学历">
						<el-select v-model="insertFrm.educationId" placeholder="请选择学历" style="width: 290px;">
							<el-option v-for="edu in education" :label="edu.name" :value="edu.id"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="6">
					<el-form-item label="地址">
						<el-cascader v-model="ssq" :options="ssqs" :props="ssqsprops" @change="handleChange" style="width: 290px;"></el-cascader>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="详细地址">
						<el-input v-model="insertFrm.address" placeholder="请输入详细地址" style="width: 580px;"></el-input>
					</el-form-item>
				</el-col>
			</el-row>

			<!-- 第五行 -->
			<el-row>
				<el-col :span="6">
					<el-form-item label="职业">
						<el-select v-model="insertFrm.workId" placeholder="请选择职业" style="width: 290px;">
							<el-option v-for="wor in work" :label="wor.name" :value="wor.id"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="6">
					<el-form-item label="工作单位">
						<el-input v-model="insertFrm.workaddress" placeholder="请输入工作单位" style="width: 290px;"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="备注信息">
						<el-input v-model="insertFrm.remarks" placeholder="请输入备注信息" style="width: 580px;"></el-input>
					</el-form-item>
				</el-col>
			</el-row>




		</el-form>



	</div>
</template>

<script>
	export default {
		data() {
			return {
				ssq: [],
				ssqs: [],
				ssqsprops: {
					value: 'id',
					label: 'name',
					children: 'list'
				},
				education: [],
				marital: [],
				source: [],
				work: [],
				insertFrm: {},
				vipgrade: []
			}
		},
		created() {
			this.vipData();
			this.educationData();
			this.maritalData();
			this.sourceData();
			this.workData();
			this.areaData();
		},
		methods: {
			UpdateData(row) {
				console.log(this.ssqs)
				this.insertFrm.pid = this.ssq[0];
				this.insertFrm.cid = this.ssq[1];
				this.insertFrm.did = this.ssq[2];

				this.axios.post('http://localhost:9993/sickperson/update', this.insertFrm).then(res => {
					if (res.data) {
						//console.log(this.insertFrm)
						this.insertFrm = row;
						//this.insertFrm = {};
						this.$message({
							message: '修改患者成功',
							type: 'success'
						});
						this.$router.push("/sickperson");
					}
				})

			},
			areaData() {
				this.axios.get('http://localhost:9993/area/findAll').then(res => {
					this.ssqs = res.data;
				})
			},
			handleChange(val) {
				this.ssq = val;
			},
			backData() {
				this.$router.back("/sickperson");
			},
			educationData() {
				this.axios.get('http://localhost:9993/education/list').then(res => {
					this.education = res.data.obj;
				})
			},
			maritalData() {
				this.axios.get('http://localhost:9993/marital/list').then(res => {
					this.marital = res.data.obj;
				})
			},
			sourceData() {
				this.axios.get('http://localhost:9993/source/list').then(res => {
					this.source = res.data.obj;
				})
			},
			workData() {
				this.axios.get('http://localhost:9993/work/list').then(res => {
					this.work = res.data.obj;
				})
			},
			vipData() {
				this.axios.get('http://localhost:9993/vipgrade/list').then(res => {
					this.vipgrade = res.data.obj;
				})
			}
		}
	}
</script>
